import { computed } from 'vue';
import permission from '@/permission';

/**
 * 权限组合函数
 * @param permissions 权限字符串或权限数组
 * @param mode 权限检查模式：'all' | 'any'
 * @returns 是否有权限
 */
export function usePermission(
  permissions: string | string[],
  mode: 'all' | 'any' = 'all'
) {
  return computed(() => {
    if (!permissions) {
      return true;
    }

    // 将单个权限字符串转换为数组
    const permissionList = Array.isArray(permissions) ? permissions : [permissions];
    
    // 根据模式选择权限检查策略
    return mode === 'any'
      ? permission.anyPermission(permissionList)
      : permission.allPermission(permissionList);
  });
}

